package cn.jxau.web.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;

import cn.jxau.bean.po.Article;
/**
 * 这个controller用作和超级管理员相关的ajax相关请求
 * @author licho
 *
 */
import cn.jxau.bean.po.User;
import cn.jxau.bean.vo.JsonResult;

@Controller
@RequestMapping("/adminajax")
@ResponseBody
public class AdminAjaxController extends BaseController {
	/**
	 * 修改uid的exist标识，代表是否将其加入黑名单
	 * @param uid
	 * @param status
	 * @return
	 */
	@RequestMapping("/convert")
	public JsonResult convert(@RequestParam(name="uid")Long uid,@RequestParam(name="status")Boolean status){
		JsonResult result=null;
		if(uid==null || status==null){
			result=renderError("参数不足！");
		}else{
			User user=new User();
			user.setTdate(null);
			user.setId(uid);
			user.setExist(status);
			boolean flag=userService.updateUserStatus(user);
			if(flag)
				result=renderSuccess("操作成功");
			else
				result=renderError("未服务器错误");
		}
		return result;
	}
	/**
	 * 根据用户id删除用户。
	 * @param uid
	 * @return
	 */
	@RequestMapping("/deleteuser")
	public JsonResult deleteUser(@RequestParam(name="uid",required=false)Long uid){
		JsonResult result=null;
			if(uid!=null){
				boolean flag=userService.deleteByUserId(uid);
				if(flag){
					result=renderSuccess("删除成功!");
				}else{
					result=renderError("未知原因，删除失败");
				}
			}else{
				result=renderError("参数不足");
			}
			return result;
	}
	
	@RequestMapping("review")
	@ResponseBody
	public JsonResult reviewArticle(Page<Article> page){
		JsonResult result=null;
		List<Article> list = articleService.getAllArticleInfo(page);
		if(list!=null&&list.size()>0){
			result=renderSuccess("获取列表成功!");
			result.addData("list", list);
		}else{
			result=renderError("文章列表为空或者发生服务器错误");
		}
		result.addData("page", page);
		return result;
	}
	
	@RequestMapping("/reviewconvert")
	public JsonResult reviewconvert(@RequestParam(name="uid")Long uid,@RequestParam(name="status")Boolean status){
		JsonResult result=null;
		if(uid==null || status==null){
			result=renderError("参数不足！");
		}else{
			Article article=new Article();
			article.setTdate(null);
			article.setId(uid);
			article.setQualified(status);
			boolean flag=articleService.updateArticleStatus(article);
			if(flag)
				result=renderSuccess("操作成功");
			else
				result=renderError("未服务器错误");
		}
		return result;
	}
}
